using System;

namespace Storage.Core
{
	internal class AddOrUpdateResponse : IStorageResponse
	{
		public AddOrUpdateResponse(bool added)
		{
			Added = added;
		}

		public byte[] Serialize()
		{
			var serializer = new FastBinarySerializer(sizeof(byte) + sizeof(Int32));
			serializer.Write(StorageOpCodes.AddOrUpdate);
			serializer.Write(Added);
			return serializer.Buffer;
		}

		public static AddOrUpdateResponse Deserialize(byte[] content)
		{
			var deserializer = new FastBinaryDeserializer(content, 1);
			return new AddOrUpdateResponse(deserializer.ReadBool());
		}

		public bool Added { get; private set; }
	}
}